Strange results from https://api.pagerduty.com/incidents

Hi,
Having a bit of a problem using the \incidents endpoint (not sure if that’s the correct term?) to get all incidents based on a single day range.

I can see in the PD portal that across all services and teams I have 49 incidents. So I would expect my sandpit code below to get all 48 in the first loop, then on the next loop offset++ it should retrieve nothing, but it loops 6 times with the .Count() decreasing by one each time.

I have tried the date filters as yyyymmdd and yyyy-mm-dd but I get the same results.

The only parts not shown in this example are the C# classes generated from the json.

Can anyone advise on what is wrong please?

Thanks

Forgot to post the results.
PD%20community2

Right now it appears that you are incrementing offset by 1 in each iteration of the for loop. On the first iteration, all incidents are retrieved, but on the second iteration, one incident is skipped, on the third iteration, two incidents are skipped etc. That is expected - offset is just an indication of the starting point from where the API should retrieve results, so when it’s set to 5, only the 5th, the 6th … the 49th incident will be returned.
If you think that you will ever need to retrieve more than a hundred incidents from the endpoint, I would recommend rewriting your for loop to increment the offset value by the same value as limit variable. For example, if limit is set to 100 and offset is set to a 100, you will retrieve the first 100 results on the first iteration. Then in the second you will increment the offset by 100 and with the limit still set to 100, you will be able to retrieve the second 100 results. I would also recommend adding logic that would break your loop when the value of more field in the returned JSON no longer equals true.
More details on our implementation of pagination here - https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTU4-pagination - hope you find it helpful!

Kat Kasianenko

1 Like

Thanks Kat for your detailed explanation, that and the link are a big help.

Regards

Hi David,

Sounds good!

I’ll go ahead and close out this ticket, and if you have any other questions, feel free to reply to this email or write in to support@pagerduty.com.

Cheers,

1 Like